package com.yjxxt.gradeList;

import org.apache.commons.lang.ObjectUtils;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
public class StudentReducer extends Reducer<IntWritable, IntWritable, Student, NullWritable> {
//public class StudentReducer extends Reducer<Text, IntWritable, Grade, NullWritable> {
    private int i = 0;
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        //jobId = context.hashCode();
    }
    @Override
    protected void reduce(IntWritable key, Iterable<IntWritable> values,Context context) throws IOException, InterruptedException
   // protected void reduce(Text key, Iterable<IntWritable> values,Context context) throws IOException, InterruptedException
    {

        //开始统计各分数段人数
        int sum = 0;
        for (IntWritable value : values) {
            sum += value.get();
        }

        Student student = new Student(i++, key.get(), sum);
        //输出人数
        context.write(student, NullWritable.get());
       /* String[] split = key.toString().split(" ");
        if (split != null && split.length == 6) {
            //开始进行数据的分拆
            //double grade = Double.parseDouble(split[3])/10;
            int id = Integer.parseInt(split[0]);
            double v_grade = Double.parseDouble(split[1]);
            double h_grade = Double.parseDouble(split[2]);
            double e_grade = Double.parseDouble(split[3]);
            double a_grade = Double.parseDouble(split[4]);
            String sex = split[5];

            Grade grade = new Grade(id, v_grade, h_grade, e_grade, a_grade, sex);
            System.out.println(grade.toString());
            //context.write(grade, NullWritable.get());
        }*/
    }
}
